package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CategoryMapper {
    //添加分类
    @Insert("insert into category values (null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer save(Category category);

    //根据分类名称查询分类名称是否存在
    @Select("select * from category where name=#{name}")
    Category findByName(String name);

    //查询所有
    @Select("select * from category order by sort")
    List<Category> findAll();

    //删除
    @Delete("delete from category where id = #{id}")
    Integer delete(Long id);

    //根据分类名称查询分类
    @Select("select * from category where name = #{name} and id != #{id}")
    Category findByName2(Category category);

    //修改
    Integer update(Category category);

    //根据type查找菜品

    List<Category> findByType(@Param("type") Integer type);

    //根据id查询菜品分类
    @Select("select * from category where id = #{id}")
    Category findById(Long id);
}
